<?php 

$menulist	= get_menu(); 
#assign data
$ci->block->view->assign("hatran",$menulist); // Gan bien $menulist vao "hatran" de gui sang ben view default.
#get template
$ci->block->view->load('default');


function get_menu($parent_id = 0, $tree = NULL){
		$ci 	=	& get_instance();
		if(!isset($tree)){$tree = array();}
		
		
		$res_parents = $ci->db->select('id,name,name_ascii,parent_id') // Get all parents
						->where('parent_id',$parent_id)
						->get('menu')
						->result();
		
		foreach ($res_parents as $k_p => $v_p) { // Loops all parents and push them into an array named "$tree" :D.
			array_push($tree, $v_p);
			
			$res_children = $ci->db->select('id,name,name_ascii,parent_id') // Get all children those have parent_id equal to parents id :D
							->where('parent_id',$v_p->id)
							->get('menu')
							->result();
			foreach ($res_children as $k_c => $v_c) { // Loops all children corresponding with their parents and then push them into the array that their parents are placed.
				array_push($tree, $v_c);
			}
		}
		
		return $tree;
		
	}
